<?php
namespace app\admin\controller;

use app\common\service\BaiduApiService;
use app\common\service\MeetingService;
use app\common\service\SignService;
use think\Exception;

class Baidumeeting extends Base
{
    public static $gid='1112';//
    //1、会议操作接口
    public function project(){
        $url='https://aip.baidubce.com/api/v1/solution/direct/meeting/project';
    }

    //创建会议
    public function createMeeting(){
        try{
            $add['meeting_name']=input('post.meeting_name');
            $add['start_time']=input('post.start_time');
            if(empty($add['start_time'])){
                $add['start_time']=date('Y-m-d H:i:s');
            }
            $add['end_time']=input('post.end_time');
            if(empty($add['end_time'])){
                $add['end_time']=date("Y-m-d", strtotime("+1 year", strtotime($add['start_time'])));
            }
            $add['gid']=self::$gid;
            $add['desc']=input('post.desc');
            $add['headimage']=input('post.headimage');
            if(isset($_POST['id']) && !empty($_POST['id'])){
                $id=input('post.id');
                $re=MeetingService::S()->saveMeeting($id,$add);
                if($re===false){
                    $id=false;
                }
            }else{
                $id=MeetingService::S()->addMeeting($add);
            }
            if($id){//写入成功像百度创建门店
                $headimage=base64EncodeImage($add['headimage']);
                $re=BaiduApiService::S()->addProject(
                    $id,
                    $add['gid'],
                    $add['meeting_name'],
                    strtotime($add['start_time']),
                    $add['desc'],strtotime($add['end_time']),
                    $headimage);
                dump($re);
            }
        }catch (Exception $ex){
            echo '接口异常:'.$ex->getMessage();
        }
    }

    //会议 查询接口
    public function queryMeeting(){
        $token=input('token');
        $re=BaiduApiService::S()->queryInfo($token);
        echo json($re);exit();
    }

    public function tes(){
        echo request()->host();die;
        dump($tr);die;
    }

    //根据会议id查询出会议人员状态
    public function meetingListByMeetingId(){
        try{
            if(empty($_POST['meeting_id'])){
                $this->ajax('202','会议id不能为空');
            }
            $where=['meeting_id'=>input('meeting_id')];
            if(isset($_POST['status'])){
                $where['status']=input('post.status');
            }
            $meetingList=SignService::S()->querySign($where);
            $this->ajax(200,'success',$meetingList);
        }catch (Exception $ex){
            echo '接口异常'.$ex->getMessage();
        }
    }


}